<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>

<link rel="stylesheet" href="../webjars/layui/2.5.6/css/layui.css"
	media="all">
<script src="../webjars/layui/2.5.6/layui.all.js" charset="utf-8"></script>
<script src="js/vue.min.js"></script>
<script type="text/javascript"
	src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.min.js"></script>
<link>
<body>

	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>上传资源</legend>
	</fieldset>
	<div style="margin-left: 40px;">
		文件名:
		<div class="layui-input-inline" style="margin-left: 22px;">
			<input type="text" name="title" lay-verify="title" autocomplete="off"
				placeholder="请输入名称" class="layui-input" id= "resource_name">
		</div>

		<button type="button" class="layui-btn" id="test1">
			<i class="layui-icon">&#xe67c;</i>选择文件
		</button>
		

	</div>
	<br>
	
<script>
layui.use('upload', function(){
  var upload = layui.upload;
   
  //执行实例
  var uploadInst = upload.render({
    elem: '#test1' //绑定元素
    ,url: '../upload/uploadResouce.s' //上传接口
    ,accept:'file'
    ,choose: function(obj){
       //将每次选择的文件追加到文件队列
       var files = obj.pushFile();
       
       //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
       obj.preview(function(index, file, result){
         console.log(index); //得到文件索引
         console.log(file); //得到文件对象
         console.log(result); //得到文件base64编码，比如图片
         $("#resource_name").val(file.name);
         
         //obj.resetFile(index, file, '123.jpg'); //重命名文件名，layui 2.3.0 开始新增
         
         //这里还可以做一些 append 文件列表 DOM 的操作
         
         //obj.upload(index, file); //对上传失败的单个文件重新上传，一般在某个事件中使用
         //delete files[index]; //删除列表中对应的文件，一般在某个事件中使用
       });
     }
    ,done: function(res){
      console.info("shangchuanchenggong");
      alert("上传成功");//上传完毕回调
    }
    ,error: function(){
      alert("上传失败");//请求异常回调
    }
  });
});
</script>








	<form class="layui-form" action="">
		
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">资源描述</label>
			<div class="layui-input-block" >
				<textarea placeholder="请输入内容" class="layui-textarea" id ="Resource_description" style="width: 800px;"></textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">资源标签</label>
			<div class="layui-input-block">
				<input type="text" name="title" lay-verify="title"
					autocomplete="off" placeholder="+添加标签" class="layui-input" id="Resource_label" style="width:800px;">
			</div>
		</div>
		
		
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">所属分类</label>
				<div class="layui-input-inline">
					<select name="modules" lay-verify="required" lay-search id="Resource_classification">
						<option value="">直接选择或搜索选择</option>
						<option value="1">网络安全</option>
						<option value="2">软件开发</option>
						<option value="3">工商管理</option>
						<option value="4">建筑设计</option>
						<option value="5">物流管理</option>
						<option value="6">人工智能</option>

					</select>
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">发布形式</label>
			<div class="layui-input-block">
				<input type="radio" name="resource_form" value="0" title="积分下载" >
				<input type="radio" name="resource_form" value="1" title="付费资源">

			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline"">
				<label class="layui-form-label">所需积分</label>
				<div class="layui-input-inline layui-input-inline">
					<select name="modules" lay-verify="required" lay-search>
						<option value="5">5</option>
						<option value="0">0</option>
						<option value="1">1</option>
						<option value="2">2</option>
						<option value="3">3</option>
						<option value="4">4</option>
						<option value="5">5</option>

					</select> <a style="color: blue">看看大家如何定价</a>
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">动态调分</label>
			<div class="layui-input-block">
				<input type="radio" name="" value="1" title="允许" checked>
				<input type="radio" name="" value="0" title="拒绝">

			</div>



			

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="button" class="layui-btn" 
						lay-filter="demo1" onclick="resouce_submit()">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
			</div>
	</form>

</body>
<script type="text/javascript">
	layui.use('.layui-form', function(){
		  var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
		  
		  
		  form.render();
	}); 
    function resouce_submit(){
    	
    	var params = new URLSearchParams();
    	var resource_name = $("#resource_name").val();//文件名
    	params.append("resource_name",resource_name);
    	var Resource_description=$("#Resource_description").val();//资源描述
    	params.append("Resource_description",Resource_description);
    	var Resource_label = $("#Resource_label").val();//资源标签
    	params.append("Resource_label",Resource_label);
    	var Resource_classification = $('#Resource_classification option:selected').val();//所属分类
    	params.append("Resource_classification",Resource_classification);
    	var Resource_form=$('input:radio[name="resource_form"]:checked').val();//发布形式
    	params.append("Resource_form",Resource_form);
    	axios.post("../upload/submitResource.s",params).then(res=>{
    		if(res.data.code == 1 ){
    			alert("提交成功");
    		}else {
    			alert("上传失败");
    		}
    	})
    	
    }
</script>
</html>